import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:lx_widgets_library/custom_view/border_radius_view.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

// 滑动器视图
class SliderView extends StatelessWidget {
  final String title;
  final String unit;
  final double min;
  final double max;
  final RxDouble value;
  final Function(double value)? onChanged;

  const SliderView({
    super.key,
    required this.title,
    required this.unit,
    required this.min,
    required this.max,
    required this.value,
    this.onChanged,
  });

  @override
  Widget build(BuildContext context) {
    return LxBorderRadiusView(
      Size(screenWidth - CONTENT_MARGIN * 2, 120.w),
      backgroundColor: GrayColor.gray2,
      radius: 8.w,
      child: Padding(
        padding: EdgeInsets.all(CONTENT_MARGIN),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                LxText(
                  title,
                  fontWeightEnum: LxFontWeightEnum.titleSmall,
                  color: Colors.white,
                ),
                Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Obx(
                      () => LxText(
                        "${value.value.toInt()}",
                        fontWeightEnum: LxFontWeightEnum.titleSmall,
                      ),
                    ),
                    SizedBox(width: 3.w),
                    LxText(
                      unit,
                      fontWeightEnum: LxFontWeightEnum.bodySmall,
                      color: Colors.white.withOpacity(0.8),
                    ),
                  ],
                )
              ],
            ),
            LxSlider(
              min: min,
              max: max,
              value: value.value,
              onChanged: (value) {
                if (onChanged != null) {
                  onChanged!(value);
                }
              },
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                LxText(
                  min.toInt().toString(),
                  fontWeightEnum: LxFontWeightEnum.bodyMedium,
                  color: Colors.white.withOpacity(0.8),
                ),
                LxText(
                  ((max - min) ~/ 2).toInt().toString(),
                  fontWeightEnum: LxFontWeightEnum.bodyMedium,
                  color: Colors.white.withOpacity(0.8),
                ),
                LxText(
                  max.toInt().toString(),
                  fontWeightEnum: LxFontWeightEnum.bodyMedium,
                  color: Colors.white.withOpacity(0.8),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
